<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/tools/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/tools/bootstrap/css/animate.min.css">
    <link rel="stylesheet" href="/tools/font-awesome/css/font-awesome.css">
    <link rel="stylesheet" href="/css/comm.css">
    <link rel="stylesheet" href="/tools/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <style>
        html{
            height: auto;
        }
        .container-fluid{
            margin-top: 2px;
        }
        .btn-box{
            border-top:1px solid #eee;
            position: fixed;
            bottom:10px;
            left:0;
            width: 100%;
            text-align: right;
        }
        .btn-box .btn{
            margin-top: 10px;
            margin-right: 10px;
        }
        .form-horizontal .form-group{
            margin-right: 0;
            margin-left: 0;
        }
    </style>
</head>
<body>
<div class="container-fluid">
    <div class="row">
        <div class="col-xs-12">
            <form class="form-horizontal row" id="app">
                <div class="form-group col-xs-12" style="height: 285px;overflow-y:scroll; overflow-x:scroll;overflow-x:hidden;">
                    <ul id="treeDemo" class="ztree"></ul>
                </div>
                <div class="btn-box col-xs-12">
                    <button class="btn btn-default" onclick="onCheck()" type="button"><i class="fa fa-save"></i>保存</button>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
<script src="/tools/jquery/jquery-3.2.1.min.js"></script>
<script src="/tools/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/tools/zTree/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="/tools/zTree/js/jquery.ztree.excheck.js"></script>
<script src="/tools/layer/layer.js"></script>
<script src="/javaScript/common.js"></script>
<script src="/javaScript/ajaxDataController.js"></script>
<script>
    <!--
    var userId  = common.request.getParam("userId");
    var setting = {
        check: {
            enable: true
        },
        data: {
            simpleData: {
                enable: true
            }
        }
    };
    var zNodes =[];
    ajaxDataController().post("/user/getResListByUserId",{userId:userId},function(data){
        if(data.status==200){
            $.each(data.resultObject,function(i,obj){
                zNodes.push({id:obj.id,pId:obj.pid,name:obj.name,open:true,checked:obj.checked=='true'?true:false});
            });
        }
    },false);

    $(document).ready(function(){
        $.fn.zTree.init($("#treeDemo"), setting, zNodes);
    });

    function onCheck(){
        var treeObj=$.fn.zTree.getZTreeObj("treeDemo"),
                nodes=treeObj.getCheckedNodes(true),
                v="";
        for(var i=0;i<nodes.length;i++){
            v+=nodes[i].id + ",";
        }
        var params = {};
        params.userId = userId;
        params.rescIds = v;
        ajaxDataController().post("/user/addUserAuth",params,function(data){
            common.layer.success("保存成功",function(){
                parent.layer.closeAll();
                parent.vue.callback(1);
            });
        });
    }
    //-->
</script>
</html>